package com.example.module_vip

import android.annotation.SuppressLint
import android.graphics.Color
import android.os.Bundle
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.lib_common.base.BaseActivity
import com.example.lib_common.base.BaseViewModel
import com.example.module_vip.adapter.VipAdapter
import com.example.module_vip.databinding.ActivityVipBinding
import com.example.module_vip.vip.AppointmentsListItem
import com.example.module_vip.vip.viewmodel.VipViewModel
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/vip/VipActivity")
@AndroidEntryPoint
class VipActivity : BaseActivity<VipViewModel, ActivityVipBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_vip


    val viewModel: VipViewModel by viewModels()
    val vipAdapter: VipAdapter by lazy { VipAdapter() }
    override fun initView() {

    }

    override fun onResume() {
        super.onResume()
        //请求数据
        questnet()
    }

    private fun questnet() {
        viewModel.getappintmentslist()
    }

    var selected = 0


    var yitongguolist = mutableListOf<AppointmentsListItem>()
    var yijujuelist = mutableListOf<AppointmentsListItem>()
    var daishenhelist = mutableListOf<AppointmentsListItem>()
    var allviplist = mutableListOf<AppointmentsListItem>()

    @SuppressLint("ResourceAsColor")
    override fun initData() {
        super.initData()
        //返回
        backactivity()


        //回调
        viplivedatacallback()

        //初始颜色
        if (selected == 0) {
            colorchange1()
        }

        //点击
        quanbushenheclick()
        daishenheclick()
        yitongguoclick()
        yijujueclick()
        addvipActivity()

    }

    private fun addvipActivity() {
        mBinding.vipTop.xinzengguanliVip.setOnClickListener {
            ARouter.getInstance().build("/vip/AddActivity").navigation()
        }
    }

    private fun viplivedatacallback() {
        viewModel.viplivedata.observe(this) {
            mBinding.rv.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(this)
            mBinding.rv.adapter = vipAdapter

            it.forEach {
                if (it.visitStatus.equals("已通过")) {
                    yitongguolist.add(it)
                }
                if (it.visitStatus.equals("已拒绝")) {
                    yijujuelist.add(it)
                }
                if (it.visitStatus.equals("待审核")) {
                    daishenhelist.add(it)
                }
                allviplist.add(it)
            }
            yitongguolist.reverse()
            yijujuelist.reverse()
            daishenhelist.reverse()
            vipAdapter.setData(allviplist)



        }
    }

    private fun backactivity() {
        mBinding.vipTop.backActivity.setOnClickListener {
            finish()
        }
    }

    private fun yijujueclick() {
        mBinding.yijujue.setOnClickListener {
            selected = 3
            if (selected == 3) {
                colorchange5()
            }

            vipAdapter.setData(yijujuelist)

        }
    }

    private fun yitongguoclick() {
        mBinding.yitongguo.setOnClickListener {
            selected = 2
            if (selected == 2) {
                colorchange4()
            }

            vipAdapter.setData(yitongguolist)
        }
    }

    private fun daishenheclick() {
        mBinding.daishenhe.setOnClickListener {
            selected = 1
            if (selected == 1) {
                colorchange3()
            }

            vipAdapter.setData(daishenhelist)

        }
    }

    private fun quanbushenheclick() {
        mBinding.quanbushenhe.setOnClickListener {
            selected = 0
            if (selected == 0) {
                colorchange2()
            }
            vipAdapter.setData(allviplist)
        }
    }

    private fun colorchange5() {
        mBinding.yijujue.setBackgroundColor(Color.parseColor("#C8E1F7"))
        mBinding.yitongguo.setBackgroundColor(Color.parseColor("#F7F8F9"))
        mBinding.daishenhe.setBackgroundColor(Color.parseColor("#F7F8F9"))
        mBinding.quanbushenhe.setBackgroundColor(Color.parseColor("#F7F8F9"))
    }

    private fun colorchange4() {
        mBinding.yitongguo.setBackgroundColor(Color.parseColor("#C8E1F7"))
        mBinding.daishenhe.setBackgroundColor(Color.parseColor("#F7F8F9"))
        mBinding.quanbushenhe.setBackgroundColor(Color.parseColor("#F7F8F9"))
        mBinding.yijujue.setBackgroundColor(Color.parseColor("#F7F8F9"))
    }

    private fun colorchange3() {
        mBinding.daishenhe.setBackgroundColor(Color.parseColor("#C8E1F7"))
        mBinding.quanbushenhe.setBackgroundColor(Color.parseColor("#F7F8F9"))
        mBinding.yitongguo.setBackgroundColor(Color.parseColor("#F7F8F9"))
        mBinding.yijujue.setBackgroundColor(Color.parseColor("#F7F8F9"))
    }

    private fun colorchange2() {
        mBinding.quanbushenhe.setBackgroundColor(Color.parseColor("#C8E1F7"))
        mBinding.daishenhe.setBackgroundColor(Color.parseColor("#F7F8F9"))
        mBinding.yitongguo.setBackgroundColor(Color.parseColor("#F7F8F9"))
        mBinding.yijujue.setBackgroundColor(Color.parseColor("#F7F8F9"))
    }

    private fun colorchange1() {
        mBinding.quanbushenhe.setBackgroundColor(Color.parseColor("#C8E1F7"))
        mBinding.daishenhe.setBackgroundColor(Color.parseColor("#F7F8F9"))
        mBinding.yitongguo.setBackgroundColor(Color.parseColor("#F7F8F9"))
        mBinding.yijujue.setBackgroundColor(Color.parseColor("#F7F8F9"))
    }

    override fun initListener() {
        super.initListener()
    }
}